package com.example.zhunongzonghe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.zhunongzonghe.dao.ZnScenicspotMapper;
import com.example.zhunongzonghe.entity.ZnScenicspot;
import com.example.zhunongzonghe.service.IZnScenicspotService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class ZnScenicspotServiceImpl extends ServiceImpl<ZnScenicspotMapper, ZnScenicspot> implements IZnScenicspotService {

    @Autowired
    ZnScenicspotMapper znScenicspotMapper;

    @Override
    public Page<ZnScenicspot> SearchAllSpot(Integer pageId, Integer pageNum, Object searchInfo) {
        Page<ZnScenicspot> page = new Page<>(pageId,pageNum);
        LambdaQueryWrapper<ZnScenicspot> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(ZnScenicspot::getSpotName,searchInfo)
                .or().like(ZnScenicspot::getSpotLocation,searchInfo)
                .or().like(ZnScenicspot::getSpotRegion,searchInfo);
        Page<ZnScenicspot> znFarmhousePage = znScenicspotMapper.selectPage(page,queryWrapper);
        return znFarmhousePage;
    }

    /**
     * 联表查询单个景点信息，包括地区表信息
     * @param spotId
     * @return
     */
    @Override
    public ZnScenicspot SearchScenicInfo(Integer spotId) {
        LambdaQueryWrapper<ZnScenicspot> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ZnScenicspot::getSpotId,spotId);
        ZnScenicspot znScenicspot = znScenicspotMapper.selectOne(wrapper);
        return znScenicspot;
    }
}
